package com.example.zzmftp.controller;

import com.example.zzmftp.service.ZzmFtpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    private ZzmFtpService zzmFtpService;

    @PostMapping("/addImageTest")
    public String addImage(@RequestParam("file") MultipartFile file){
        try {
           return zzmFtpService.uploadFile(file);
        }catch (Exception e){
            e.printStackTrace();
        }
        return "上传失败";
    }


    @GetMapping("/downloadFile")
    public void downloadFile(@RequestParam("filePath") String filePath, HttpServletResponse response){
        zzmFtpService.downloadFile(filePath,response);
    }

    @PostMapping("/deleteFile")
    public void deleteFile(@RequestParam("filePath") String filePath){
        zzmFtpService.deleteFile(filePath);
    }
}
